<template>
	<view class="content pc-tou-gao " >
		<view class="scroll-fix" >

		
			<view class="d-kuan-juzhong ">
				<!--头部-->
				<view class="d-kuan pc-dingbu ">
					<DToubu 
					@login-success="handleLoginSuccess" 
					@logout-success="handleLogout"
					:dengluxianshi="denglu_xianshi"
					@update-dengluxianshi="handleUpdateDengluxianshi"
					@www-data="wwwdataget"
					></DToubu>
					
				</view>
				


				<!--头部-->
				<!--下面内容-->
				<view class="d-kuan d-clear">
					<uv-row customStyle="margin-bottom: 10px" :gutter="10">
						<!-- #ifdef H5 -->
						<uv-col span="2" class="pc-yincang">
							<!--左边导航-->
							<view class="d-daohang d-you-10 pc-yincang d-y-gundong d-shang-20" id="zuo-daohang" :style="{height: leftNavHeight}">
								<view class="d-daohang-5 " >
									<Ddaohang 
									@denglu-fabu="denglu_fabu"
									
									></Ddaohang>
								</view>
							</view>
						</uv-col>
						<!-- #endif -->

						<uv-col :span="kuan_shu">
							
							<view class="d-shang-50">
								<view class="d-waikuang-20-0 d-beijing-bai ">
									<!--头部-->
									<Dfanhui
									:title="wwwData && wwwData.setting && wwwData.setting.jifen"
									>

									</Dfanhui>
									<view class="d-neikuang-40">
										<view class="d-kuan d-juzhong d-wenzi-30 d-jiacu" style="color: #6a488a;">
											{{ u_data.wo && u_data.wo.score }}{{ wwwData && wwwData.setting && wwwData.setting.jifen }}
										</view>
									</view>
								</view>
								<view class="d-waikuang-20-0 d-beijing-bai ">

								    <view class="d-neikuang-40">
										<view v-if="payjifen" class="d-kuan">
											<uv-row customStyle="margin-bottom: 10px; flex-wrap: wrap" :gutter="20">
												<uv-col v-for="(list,index) in quan_payjifen" :key="index" span="6">
													<view class="demo-layout bg-purple-light " style="margin-bottom: 20px;" @click="goumai_jifen(list.id,list.jifen,list.zengsong_jifen,list.youhui_jiage)">
														<view class="d-wenzi-20 d-jiacu d-juzhong d-shang-10" style="color: #6a488a;">
															{{ list.jifen }} {{ wwwData && wwwData.setting && wwwData.setting.jifen }}
														</view>
														<view class="d-wenzi-16 d-juzhong d-shangxia-10" style="color: #6a488a;">
															赠送 {{ list.zengsong_jifen }} {{ wwwData && wwwData.setting && wwwData.setting.jifen }}
														</view>
														<view class="d-wenzi-12 d-juzhong d-shangxia-10" style="color: #7c7f7c;">
															<view class="d-xie-shanchuxian">原价 {{ list.jiage }} 元</view>
														</view>
														<view class="d-wenzi-12 d-juzhong d-shangxia-10" style="color: #e57b34; ">
															优惠价：{{ list.youhui_jiage }} 元
														</view>
													</view>
												</uv-col>
												
												
											</uv-row>
										</view>
										<view v-else>
											<view>
												请到网站后台的 应用商城 安装“积分购买”插件。
											</view>
										</view>


									</view>
								</view>
								

							</view>
							
							
							
															
							
							<view class="pc-neikuang-20-list" >
								
							</view>
							
							<!--头部背景-->
							
							
						</uv-col>
						<!-- #ifdef H5 -->
						<uv-col span="3" class="pc-yincang">
							<view class="d-daohang d-you-10 pc-yincang d-shang-20" id="zuo-daohang" :style="{height: leftNavHeight}">
								<view class="d-you-kuang">
									
								</view>
							</view>
						</uv-col>
						<!-- #endif -->
					</uv-row>

					

				</view>
				<!--下面内容-->


			</view>

			<view class="d-clear"></view>
		
		</view>
		<uv-modal ref="jifen" :title="title_jifen" :showCancelButton="true" @cancel="cancelJifen" @confirm="confirm">
			<view class="slot-content">
				<rich-text :nodes="content"></rich-text>
			</view>
		</uv-modal>
		<Dzhifu
		:show="show"
		:payType="payType"
		:jine="jine"
		@close="show = false"
		@uidapi="getUid_api"
		@tieapi="get_api"
		:mark="mark"
		:quanid="cid"
		:jifen_data="jifen_data"
		></Dzhifu>
		
		

	</view>
</template>

<script>
    import Api from '@/utils/api.js'; 
	import QuanApi from '@/utils/quan_api.js';
	import UApi from '@/utils/u_api.js';
	import { getRequest,postRequest } from '@/utils/wxRequest.js';
    //引入组件 d-toubu
    import DToubu from '@/components/d-toubu/d-toubu.vue'
	import Ddaohang from '@/components/d-daohang/d-daohang.vue'
	import Dweibu from '@/components/d-weibu/d-weibu.vue'
	import Dfanhui from '@/components/d-fanhui/d-fanhui.vue'
	import Dzhifu from '@/components/d-zhifu/d-zhifu.vue'
	
	
	export default {
		data() {
			return {
				title: 'Hello',
				leftNavHeight: '500rpx', // 默认高度
                rightColWidth: '300px', // 默认宽度
				rightColLeft: '0px', // 添加这个属性
				uiddata:{},
				erjidata:[],
				erjiindex:'',//当前激活的二级菜单索引
				activeIndex: -1, // 当前激活的一级菜单索引
				zhishi_tuijian_data:[], // 知识推荐数据
				zhishi_daohang_list:[], // 知识导航列表
				zhishi_list:[], // 知识列表
				haibao_data:[], // 海报数据
				imageSize: {
        		    width: 0,
        		    height: 0
        		},
				tubiaolist: 
				['integral', 'kefuv-ermai', 'coupon', 'gift', 'scan',
					'pause-circle', 'volume-off', 'email', 'list'
				],
				denglu_xianshi:0, // 登录显示

				tiezi_list:[], // 帖子列表

				currentPage: 1, //下拉加载
    			pageSize: 12, //下拉加载
    			isLoading: false, //下拉加载
    			noMoreData: false, //下拉加载
				
				kuan_shu: 7, //格大小
				uid: '', // 用户ID - 初始化为空字符串，将在onLoad/onShow中设置
				swiperHeight: '250',
				gao: '20', //图片高度
				
				quan_data:[],
				
				shenhe_shu:0,//审核帖子数量
				u_data:[], // 用户信息
				dataLoaded: false,
			
				guanzhu_panduan:0,
				payjifen:1, // 是否开启支付积分
				wwwData:{},
				quan_payjifen:[],
				content:'',
				title_jifen:'',
                pendingJifen: null,

				jifen_data:{}, // 积分数据
				mark:'', // 自定义参数
				show:false, // 弹窗显示
            }
		},
		components: {
  		    DToubu,
			Ddaohang,
			Dweibu,
			Dfanhui,
			Dzhifu,
  		},
		mounted() {
			// 确保在组件挂载后更新uid
			// console.log('Component mounted, checking uid...');
			const storeUid = this.$store.state.memberuid;
			if (storeUid && !this.uid) {
				this.uid = storeUid;
				// console.log('UID set from store in mounted:', this.uid);
			}
			
    	    
			this.getRightColWidth(); // 添加这行
    	    // 添加窗口大小变化监听
			// #ifdef H5
			this.setLeftNavHeight();
    	    window.addEventListener('resize', this.setLeftNavHeight);
			window.addEventListener('resize', this.getRightColWidth); // 添加窗口大小变化监听
			// #endif
			var e = this;
			//this.onImageLoad(e);
    	},
    	beforeDestroy() {
    	    // 移除监听
			// #ifdef H5
    	    window.removeEventListener('resize', this.setLeftNavHeight);
			window.removeEventListener('resize', this.getRightColWidth); // 添加这行
			// #endif
    	},
		onShow() {
			// console.log('Component shown, updating uid...');
			const storeUid = this.$store.state.memberuid;
			// console.log('Store memberuid:', storeUid);
			this.uid = storeUid;
			// console.log('UID set in onShow:', this.uid);

			if(!storeUid){
				// console.log('No uid in store, showing login prompt');
				this.denglu_xianshi = 1;
				this.godenglu(); // 暂时注释掉自动跳转，便于调试
			}
			this.get_app_list(); // app信息

			//this.getShenhe_shu_api();
			
		},
		onLoad(e) {
			// console.log('Component loaded with params:', e);
			// 优先使用路由参数中的uid
			if (e && e.uid) {
				this.uid = e.uid;
				// console.log('UID set from route params:', this.uid);
			} else {
				// 如果路由参数中没有uid，则从store获取
				const storeUid = this.$store.state.memberuid;
				if (storeUid) {
					this.uid = storeUid;
					// console.log('UID set from store in onLoad:', this.uid);
				} else {
					// console.log('No uid available in route params or store');
				}
			}
			
			// 只有在有uid的情况下才调用API
			if (this.uid) {
				this.getu_api();
				// 初始化昵称数据
				this.setInitialNicheng();
			
			} else {
				console.warn('Cannot call getu_api: uid is not available');
			}
			
		},
		computed: {
		  yidenglu() {
		    return (this.$store.state.memberuid && this.$store.state.keycode) ? 1 : 0;
		  },
		  touxiang() {
		    return this.$store.state.member? this.$store.state.member.avatar : '';
		  },
		  name1() {
		    return this.$store.state.member? this.$store.state.member.name : '';
		  },
		  pc() {
		    return this.$store.state.kuan.pc;
		  },
		},
		onReachBottom() {
  			this.onReachBottom(); //下拉加载分页
  		},

		methods: {
			//图片
			onImageLoad(e, index) {
				// 获取系统信息
				const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    const windowHeight = systemInfo.windowWidth;
				if(windowHeight >=920){
					var gao = 30;
					
				} else {
					var gao = 0;
				}


				this.$nextTick(() => {
        		    const query = uni.createSelectorQuery().in(this);
        		    query.select('#tupian-'+index).boundingClientRect(data => {
        		        if (data && data.width > 0 && data.height > 0) {
        		            this.$set(this.haibao_data[index], 'imageSize', {
        		                width: data.width,
        		                height: data.height + gao
        		            });
							// console.log('图片尺寸:', this.haibao_data[index].imageSize);
        		        } else {
        		            console.warn(`图片${index}尺寸获取失败`);
        		            this.$set(this.haibao_data[index], 'imageSize', {
        		                width: 300,
        		                height: 200
        		            });
        		        }
        		    }).exec();
        		});

    		},
			getRightColWidth() {
				// 获取系统信息
				const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    const windowWidth = systemInfo.windowWidth;
				var d = this;

                this.$nextTick(() => {
				if(this.pc){
					d.gao = 20;
					d.kuan_shu = 7;
					d.swiperHeight = '250';
				} else {
					d.gao = 10;
					d.kuan_shu = 12;
					d.swiperHeight = '120';

				}
				// console.log('窗口高度:', windowWidth);

                /* const query = uni.createSelectorQuery().in(this);
                 query.select('#youbiankuan').boundingClientRect(rect => {
                   if (rect) {
                    
					 	this.rightColWidth = `${rect.width-80}px`;
                    	this.rightColLeft = `${rect.left}px`; // 计算左侧位置
                    	// console.log('右侧列位置:', this.rightColWidth);
                   }
                 }).exec();*/
               });
            },

			
			
			setLeftNavHeight() {
        	    // 获取系统信息
        	    const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    const windowHeight = systemInfo.windowHeight;
        	    const headerHeight = 70; // 头部高度估计值
        	    const calculatedHeight = windowHeight - headerHeight;
				
        	    // 设置左边导航高度
        	    this.leftNavHeight = `${calculatedHeight}px`;
        	},
			
			
			handleLoginSuccess() {
  			  this.$forceUpdate();
  			},
			
			
			
			
			denglu_fabu(){
				if(this.yidenglu == 0){
					this.denglu_xianshi = 1;
					
				} else {
					this.denglu_xianshi = 0;
						
				}
				
				// console.log('发布登录',this.denglu_xianshi);
				
			},
			// 更新判断是否登录
			handleUpdateDengluxianshi(value) {
			  this.denglu_xianshi = value;
			  
			  // console.log('关闭登录',this.denglu_xianshi);
			},
			// 退出登录
			handleLogout() {
 			  
 			  this.godenglu(); // 暂时注释掉自动跳转，便于调试
			   
 			},
			
			
			
			
			
			//个人信息
			getu_api(){
				// console.log('Calling getu_api with uid:', this.uid);
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				const data = {
						uid: this.uid,
						api_auth_uid: this.uid,
						api_auth_code: keycode,
					}
				var get_data = getRequest(UApi.getU(),data);
				var res;
				get_data.then(duixin_data => {
					res = duixin_data;
					if(res.data.code) {
						if(this.uid){
							//this.u_data = res.data.data.wo;
						} else {
							//this.u_data = res.data.data.u;
						}
						this.u_data = res.data.data;
						//this.u_data = res.data.data;
						this.dataLoaded = true;
						
					}
				})

			},
			//跳转个人信息
			godenglu(){
				//保持url到缓存，名称是u_url
				uni.setStorageSync('go_url', this.$route.fullPath);
				uni.navigateTo({
					url: '/pages/u/denglu',
				})
			},

			tuichu(){
				uni.showToast({
					title: "退出成功",
					icon: 'success',
					
				})

				uni.removeStorageSync('userInfo');
				uni.removeStorageSync('memberuid');
				uni.removeStorageSync('keycode');
				uni.removeStorageSync('member');
				// 通过 mutations 更新 Vuex 状态
				this.$store.commit('setMember', {});
    			this.$store.commit('setMemberUid', '');
    			this.$store.commit('setKeycode', '');
				//this.yidenglu = 0;
				// 触发退出事件
				this.$emit('logout-success');
				//退出跳转到首页
				uni.reLaunch({ url: "/pages/index/index" });
			},
			// 设置初始昵称
			setInitialNicheng() {
				if(this.u_data && this.u_data.wo && this.u_data.wo.name && !this.uiddata.nicheng){
					this.uiddata.nicheng = this.u_data.wo.name;
				}
			},
			// 昵称设置
			d_shezhi() {
				var duixin = this;
				var nicheng = duixin.uiddata && duixin.uiddata.nicheng;
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				var datas = "&is_ajax=1&data[name]="+nicheng;
				var postRenzhengRequest = postRequest(Api.postZiliao(uid,keycode),datas);
					postRenzhengRequest.then(response => {
						if (response.data.code == 1) {
							
							uni.showToast({
								title: response.data.msg,
								icon: 'success',
								success: function () {
								}
							});
							this.getu_api();
						} else {
							uni.showToast({
								title: response.data.msg,
								icon: 'error',
							});
						}
					});
			},
			// getapp get_app()
			get_app_list(){
				var get_data = getRequest(QuanApi.get_app());
				var res;
				get_data.then(duixin_data => {
					res = duixin_data;
					if(res.data.code) {
				
						this.applist = res.data.data;
						//判断数据里面是有 payjifen 字段，如果有那么赋值给 payjifen=1 那么没有赋值给 payjifen=0
						if(this.applist && this.applist.payjifen){
							this.payjifen = 1;
							this.get_payjifen_list_data();//获取购买积分
						} else {
							this.payjifen = 0;
						}
						//console.log('app:',this.payjifen);
						
					}
				})
			},
			wwwdataget(e){
				this.wwwData = e;
			},
			//获取购买积分
			get_payjifen_list_data(){
				var get_data = getRequest(QuanApi.get_payjifen_list());
				var res;
				get_data.then(duixin_data => {
					res = duixin_data;
					if(res.data.code) {
						this.quan_payjifen = res.data.data;
					}
				})
			},
			//购买积分
			goumai_jifen(id,jifen,zengsong_jifen,youhui_jiage){
				// 获取当前url
				var currentUrl = this.$route.fullPath;
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				//console.log('当前url:', currentUrl);
				// 储存当前url到缓存，名称是go_url
				uni.setStorageSync('goumai_jifen_url', currentUrl);
				// 判断 用户是否有金额（数值化比较，避免字符串比较）
				const balanceRaw = this.u_data && this.u_data.wo && this.u_data.wo.money;
				const balance = Number(balanceRaw) || 0;
				const price = Number(youhui_jiage) || 0;
				if (balance < price) {
					/*uni.showModal({
						title: '余额不足',
						content: '当前余额不足，请先充值后再购买',
						confirmText: '去充值',
						cancelText: '取消',
						success: (res) => {
							if (res.confirm) {
								// 记录返回地址并跳转充值页
								uni.setStorageSync('go_url', currentUrl);
								uni.navigateTo({ url: '/pages/u/jine' });
							}
						}
					});*/
					this.goumai_jifen_zhifu(id,jifen,zengsong_jifen,youhui_jiage); //购买积分直接支付
					return;
				}
				
				// 记录待确认的购买参数
				this.pendingJifen = { id, jifen, zengsong_jifen, youhui_jiage };
				
				// 计算单位，避免未加载时拼接报错
				const unit = (this.wwwData && this.wwwData.setting && this.wwwData.setting.jifen) ? this.wwwData.setting.jifen : '';
				this.title_jifen = '购买' + jifen + unit;
				// 弹窗内容
				
				this.content = '支付 ' + youhui_jiage + ' 元 确认吗？\n\n';
				this.$refs.jifen.open();
				// 确认购买
				
			},
			// 拉起支付
			getPayzhifu(data,urldata){
				//console.log('弹出2');
				var duixin = this; 
				// #ifdef MP
				var getPayidRequest = getRequest(Api.getPayid(data.code,urldata));
				// #endif
				// #ifdef H5
				var getPayidRequest = getRequest(Api.getPayid(data.code,urldata));
				// #endif
				getPayidRequest.then(response => {
					//console.log('支付weixin',response); 
					if (response.data.code) {
						// #ifdef H5
							//duixin.getH5payzhifu(response.data.data,urldata);
							duixin.getWeixinMiyueData(response.data.data);
							
						// #endif
						// #ifdef MP
						// 小程序
						wx.requestPayment({
							"timeStamp": response.data.data.timeStamp,
							"nonceStr": response.data.data.nonceStr,
							"package": response.data.data.package,
							"signType": "MD5",
							"paySign": response.data.data.paySign,
							"success":function(res){
								
								duixin.getu_api();
								
							},
							"fail":function(res){
								//console.log(res);
								wx.showModal({
									showCancel: false,
									content: res.err_desc+"："+res.errMsg
								})
							}
							
						})
						// #endif
					  //console.log('支付',response.data); 
					  //duixin.quanzishuxing = response.data.data
					} else {
					  uni.showToast({
					  	icon: 'none',
					  	title: response.data.msg,
					  	duration: 1000
					  });
					}
				});
			},
			
			async getWeixinMiyueData(data){
				
				var duixin = this;
				// #ifdef H5
				try {
					await this.$ensureWxLoaded();
				} catch (e) {
					console.error('JSSDK加载失败：', e);
					uni.showToast({ title: '微信JSSDK加载失败', icon: 'none' });
					return;
				}
				// #endif
				// #ifdef H5
				const wxRef = window.wx || (window.duixin && window.duixin.$wx);
				if (!wxRef || typeof wxRef.config !== 'function') {
					console.error('微信JSSDK未正确加载：wxRef.config 不可用', wxRef);
					uni.showToast({ title: '微信JSSDK不可用', icon: 'none' });
					return;
				}
				// #endif
				var danqianurls = uni.getLaunchOptionsSync();
				//var danqianurls = '/'+danqianurls.path+'?id='+danqianurls.query.id;
				var danqianurls = '/'+danqianurls.path;
				
				const url = decodeURIComponent(window.location.href);
				var urljia = danqianurls;
				
				var getWeixinmiyueRequest = getRequest(Api.getWeixinfengxiangmiyue(url));
				 
				getWeixinmiyueRequest.then(response => {
					
					if (response.data.code == 1) {
						
						var weixin = response.data.data;
						//console.log('充值H5weixin',weixin);
						wxRef.config({
						  debug: false,//true
						  appId: weixin.appId,
						  timestamp: weixin.timestamp,
						  nonceStr: weixin.nonceStr,
						  signature: weixin.signature,
						  jsApiList: [
						    // 所有要调用的 API 都要加到这个列表中
						    
						    // 这里需要自己按微信文档来写参数
						    "updateAppMessageShareData", 
							"updateTimelineShareData",
							'checkJsApi', //判断当前客户端版本是否支持指定JS接口  
							'onMenuShareAppMessage', //分享接口  
							'getLocation', //获取位置  
							'openLocation', //打开位置  
							'scanQRCode', //扫一扫接口  
							'chooseWXPay', //微信支付  
							'chooseImage', //拍照或从手机相册中选图接口  
							'previewImage', //预览图片接口  
							'uploadImage' //上传图片  
						  ]
						});
						wxRef.ready(function () {
							//duixin.getPayzhifu(dataa,datab);
							//console.log('支付data',data); 
							
							// config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
							wxRef.checkJsApi({
								jsApiList: ['chooseWXPay'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
								success: function(res) {
									//console.log('支付res',res); 
								}
							});
							// 调用微信支付接口
							wxRef.chooseWXPay({
								timestamp: data.timeStamp,    // 时间戳
								nonceStr: data.nonceStr,      // 随机串
								package: data.package,        // 订单详情扩展字符串
								signType: 'MD5',                // 签名方式
								paySign: data.paySign,           // 签名
								success: function(res) {
									// 支付成功后的回调函数
									//duixin.getMemberpay(res);
									duixin.getu_api();
									
								},
								fail: function(res) {
									// 支付失败后的回调函数
									console.error('Payment failed', res);
									
									setTimeout(() => {
										uni.reLaunch({
											//url: '/pages/fail/fail'
										})
									}, 500)
								}
							})
							
						});
						wxRef.error(function(res){
						  //console.log('weixinres',res); 
						});
					} else {
					    duixin.setData({
							displaySwiper: "none"
					    });
					}
				});
			},
			goumai_jifen_zhifu(id,jifen,zengsong_jifen,youhui_jiage){
				//
				//console.log('id,jifen,zengsong_jifen,youhui_jiage',id,jifen,zengsong_jifen,youhui_jiage);
				var duixin = this; 
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				//判断是否登录
				if(!uid || !keycode){
					uni.showToast({
						title: '请先登录',
						icon: 'error',
					});
					return;
				}
				// 充值金额
				this.jine = youhui_jiage;
				this.jifen_data = {
					id: id,
					jifen: jifen,
					zengsong_jifen: zengsong_jifen,
					youhui_jiage: youhui_jiage,
				}
				// 执行购买接口 
				// 自定义参数：积分id
				this.mark = 'my-payjifen_buy-'+id;
				this.quanid = id;
				//弹出充值页面
				var mark = 'my-payjifen_buy-'+id;
				this.mark = mark;
				// #ifdef H5
				const userAgent = navigator.userAgent.toLowerCase();
				if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android/.test(userAgent)) {
					// 移动端
					//console.log('移动端',userAgent)
					var h5datas = "is_ajax=1&pay[money]=" + youhui_jiage + "&pay[type]=weixin&pay[is_xcx]=1&h5=1&pay[mark]="+mark;
					//判断是否在微信浏览器中
				    if(/micromessenger/.test(userAgent)){
						// 微信浏览器中
						//弹出提示，加载中...
						uni.showToast({
							title: '加载中...',
							icon: 'loading',
							duration: 4000
						});
						//console.log('移动端',userAgent)
						var h5datas = "is_ajax=1&pay[money]=" + youhui_jiage + "&pay[type]=weixin&pay[is_xcx]=1&h5=1&pay[mark]="+mark;
						
					} else {
						// 显示弹窗
						this.show = true;
						return;
					}
				} else {
					// pc端
					//console.log('PC端',userAgent)
					//var h5datas = "is_ajax=1&pay[mark]=recharge&pay[money]=" + money + "&h5=2";
					// 弹出 Dzhifu 组件
					// 显示弹窗
					this.show = true;
					return;
				}
				// #endif
				var datas = "is_ajax=1&pay[money]=" + youhui_jiage + "&pay[type]=weixin&pay[is_xcx]=1&pay[mark]="+mark;
				
				var postPayRequest = postRequest(Api.postPay(uid,keycode),datas);
				postPayRequest.then(response => {
					if (response.data.code) {
						console.log('弹出0'); 
						// #ifdef MP
						duixin.getPayzhifu(response.data,datas);
						// #endif
						// #ifdef H5
						duixin.getPayzhifu(response.data,h5datas);
						// #endif
						
						
					} else {
						uni.showToast({
							icon: 'none',
							title: response.data.msg,
							duration: 1000
						});
					}
				});
				
				
			},
			confirm(){
				// 点击弹窗确认，触发购买接口
				const p = this.pendingJifen;
				if (!p) {
					this.$refs.jifen.close();
					return;
				}
				this.goumai_jifen_api(p.id, p.jifen, p.zengsong_jifen, p.youhui_jiage);
				// 关闭弹窗
				this.$refs.jifen.close();
			},
			goumai_jifen_api(id,jifen,zengsong_jifen,youhui_jiage){
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				//判断是否登录
				if(!uid || !keycode){
					uni.showToast({
						title: '请先登录',
						icon: 'error',
					});
					return;
				}
				// 执行购买接口 get_buy_jifen
				var datas = "&is_ajax=1&data[id]="+id+"&data[jifen]="+jifen+"&data[zengsong_jifen]="+zengsong_jifen+"&data[youhui_jiage]="+youhui_jiage;
				var postRenzhengRequest = postRequest(QuanApi.get_buy_jifen(uid,keycode),datas);
					postRenzhengRequest.then(response => {
						if (response.data.code == 1) {
							
							uni.showToast({
								title: response.data.msg,
								icon: 'success',
								success: function () {
								}
							});
							this.getu_api();
						} else {
							uni.showToast({
								title: response.data.msg,
								icon: 'error',
							});
						}
					});
				// 调用购买积分接口
				// console.log('购买积分:',id,jifen,zengsong_jifen,youhui_jiage);
			},
			// 取消弹窗
			cancelJifen(){
				// 关闭模态框并清理必要状态
				this.$refs.jifen.close();
			},
			get_api(){
				this.getu_api();
			}







		}
	}
</script>

<style>
/*引入css main.css*/

	.content {
		
		
		display: flex;
		flex-direction: column;
		/*align-items: center;*/
		
		background-color: #f3f3f3;
		
		margin-bottom: 0px;
		
		/*height: 100vh;*//* 添加全屏 */
		/*width: 100vw;*/ /* 添加全屏*/
		box-sizing: border-box;
		overflow-x: hidden;

		
		

	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	/* 屏幕宽度大于786px时隐藏uni-page-head */
    @media (min-width: 786px) {
        uni-page-head {
            display: none !important;
            opacity: 0 !important;
            height: 0 !important;
            visibility: hidden !important;
        }
    }
	/*.d-daohang{
		
		width: 600rpx;
	}*/
	/* 添加在style部分 */
	.d-daohang-zuo {
    position: fixed;
    left: 0;
    
    width: 180rpx;
    height: calc(100vh - 70rpx);
    background: #f5f5f5;
    z-index: 100;
	box-shadow: 2px 0 5px rgba(177, 177, 177, 0.1);
  }
  
  .d-daohang-you {
    position: fixed;
    left: 180rpx;
    
    width: 180rpx;
    height: calc(100vh - 70rpx);
    background: #fff;
    z-index: 100;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
  }
   
   
   
   
   
   
   
   
   
   
   
 
   
  .d-erji-item {
    height: 60rpx;
    line-height: 60rpx;
    padding: 0 20rpx;
   /* border-bottom: 1px solid #f0f0f0;*/
  }
  
  .d-erji-item:active {
    background: #f5f5f5;
  }
  .you-guding {
	position: fixed;
	top: 0; /* 根据头部高度调整 */
	/*box-shadow: -2px 0 5px rgba(0,0,0,0.1);*/
	transition: all 0.3s ease;
}
/* 大于786px时的样式 */
@media screen and (min-width: 1024px) {
	.d-bianhua-10 {
		padding: 30px;
	}
	.pc-zuo-520 {
		margin-left: 520rpx;
	}
	.you-guding {
		position: fixed;
			
		top: 60px; /* 根据头部高度调整 */
		/*box-shadow: -2px 0 5px rgba(0,0,0,0.1);*/
		transition: all 0.3s ease;
	}
		
	
}

  .demo-layout.bg-purple-light {
    border: 1px solid #ccc;
    border-radius: 10px;
  }

  .demo-layout.bg-purple-light:hover,
  .bg-purple-light:hover {
    border-color: #e23333; /* 红色 */
    transition: border-color 0.2s ease;
  }

	
/* #ifdef H5 */
.d-xie-shanchuxian {
  position: relative;
}
.d-xie-shanchuxian::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  border-top: 1px solid currentColor;
  transform: rotate(-12deg);
  transform-origin: center;
  opacity: 0.85;
  pointer-events: none;
}
/* #endif */
/* #ifndef H5 */
.d-xie-shanchuxian {
  text-decoration: line-through; /* 非 H5 平台回退为水平删除线 */
}
/* #endif */
</style>
